package org.karelun.gef.figure;

import org.eclipse.draw2d.AbstractBorder;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.karelun.gef.helper.ImageResource;

public class ClassFigure extends NodeFigure {
	
	private class AttrFigureBorder extends AbstractBorder{

	public Insets getInsets(IFigure figure) {
		return new Insets(1,0,0,0);
	}

	public void paint(IFigure figure, Graphics graphics, Insets insets) {
//		graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(), tempRect.getTopLeft());
		graphics.drawLine(getPaintRectangle(figure, insets).getTopLeft(),
				getPaintRectangle(figure, insets).getTopRight());
	}
		
	}
	private class AttrFigure extends Figure{
		
		public AttrFigure(){
			ToolbarLayout layout=new ToolbarLayout();
			layout.setMinorAlignment(ToolbarLayout.ALIGN_TOPLEFT);
			layout.setStretchMinorAxis(false);
			setLayoutManager(layout);
			layout.setSpacing(2);
			setBorder(new AttrFigureBorder());
		}
	}
	
	private AttrFigure attrFigure=new AttrFigure();
	
	private AttrFigure methodFigure=new AttrFigure();
	
	public ClassFigure(){
		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);
		setBorder(new LineBorder(ColorConstants.black,1));
		setOpaque(true);
		
		label=new Label(getImage());
		add(label);
		add(attrFigure);
		add(methodFigure);
		
		setToolTip(new Label("this is class figure")); //$NON-NLS-1$
	}
	
	private Image getImage() {
		return ImageResource.getImage(ImageResource.CLASS);
	}
		
	public AttrFigure getAttributeFigure() {
		return attrFigure;
	}
	
	public AttrFigure getMethodFigure() {
		return methodFigure;
	}
	
	protected void setBGColor(Color color) {
		setBackgroundColor(color);
	}

	
}